﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UCL.Powersource.ViewModels.Analysis;

namespace UCL.Powersource.Views.Analysis
{
    /// <summary>
    /// Interaction logic for GeneralTeamStats.xaml
    /// </summary>
    [Export(typeof(OneTeamOverTimeTableViewOld))]
    public partial class OneTeamOverTimeTableViewOld : UserControl
    {

        OneTeamOverTimeTableViewModel VM { get { return (OneTeamOverTimeTableViewModel)DataContext; } }

        public OneTeamOverTimeTableViewOld()
        {
            InitializeComponent();
            this.Loaded += OneTeamOverTimeTableView_Loaded;
            this.Unloaded += OneTeamOverTimeTableView_Unloaded;
        }

        void OneTeamOverTimeTableView_Unloaded(object sender, RoutedEventArgs e)
        {
            if (VM != null) VM.Deactivate();
        }

        void OneTeamOverTimeTableView_Loaded(object sender, RoutedEventArgs e)
        {
            if (VM != null) VM.Activate();
        }

        private void MyTable_AutoGeneratedColumns_1(object sender, EventArgs e)
        {
            var grid = (DataGrid)sender;
            if (grid.Columns.Count > 0)
                grid.Columns[0].Visibility = System.Windows.Visibility.Hidden;
        }

        private void MyTable_AutoGeneratingColumn_1(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            if (e.Column is DataGridTextColumn)
            {
                var source = ((DataGrid)sender).ItemsSource as DataView;
                if (source != null)
                {
                    var sourceTable = source.Table as DataTable;
                    var bin = ((DataGridTextColumn)e.Column).Binding as Binding;
                    if (bin != null)
                    {
                        if (sourceTable.Columns[bin.Path.Path].ExtendedProperties.Count > 0)
                            bin.StringFormat = (string)sourceTable.Columns[bin.Path.Path].ExtendedProperties["FormatString"];
                    }
                }
            }
        }
    }
}
